package mil.af.amc.adpetracker.web.decorators;

import mil.af.amc.adpetracker.model.User;
import mil.af.amc.adpetracker.util.LinkBuilder;
import org.displaytag.decorator.TableDecorator;

/**
 * Please fill in this Javadoc
 *
 * @author Jason Ferguson
 */
public class UserDecorator extends TableDecorator {

    public String getDisplayName() {

        User user = (User) getCurrentRowObject();
        return user.getDisplayName();
    }

    public String getOrganization() {

        User user = (User) getCurrentRowObject();
        return user.getOrganization();

    }

    public String getOrganizationName() {

        User user = (User) getCurrentRowObject();
        return user.getAssignedOrganization().getName();
    }

    public String getPrimaryCustodianActions() {

        User user = (User) getCurrentRowObject();

        StringBuffer sb = new StringBuffer();

        LinkBuilder viewLink = new LinkBuilder();
        viewLink.setName("View");
        viewLink.setBaseUrl("userAction.do");
        viewLink.addParameter("method", "viewCustodian");
        viewLink.addParameter("userId", user.getId());

        sb.append(viewLink.getLink(LinkBuilder.LINK_TEXT, true));

        return sb.toString();

    }

    public String getAlternateCustodianActions() {

        User user = (User) getCurrentRowObject();

        StringBuffer sb = new StringBuffer();

//        LinkBuilder viewLink = new LinkBuilder();
//        viewLink.setName("View");
//        viewLink.setBaseUrl("userAction.do");
//        viewLink.addParameter("method", "viewCustodian");
//        viewLink.addParameter("userId", user.getId());

        //sb.append(viewLink.getLink(LinkBuilder.LINK_TEXT, true));
        sb.append("View");
        sb.append("&nbsp;");

        LinkBuilder deleteLink = new LinkBuilder();
        deleteLink.setName("Delete");
        deleteLink.setBaseUrl("javascript:confirmRemoveAlternateCustodian(" + user.getId() + ")");
        sb.append(deleteLink.getLink(LinkBuilder.LINK_TEXT, true));

        return sb.toString();

    }

    public String getAccountProfileActions() {

        User user = (User) getCurrentRowObject();

        StringBuffer sb = new StringBuffer();

        LinkBuilder viewLink = new LinkBuilder();
        viewLink.setName("View");
        viewLink.setBaseUrl("userAction.do");
        viewLink.addParameter("method", "viewCustodian");
        viewLink.addParameter("userId", user.getId());

        sb.append(viewLink.getLink(LinkBuilder.LINK_TEXT, true));
        sb.append(" ");

        LinkBuilder deleteLink = new LinkBuilder();
        deleteLink.setName("Delete");
        deleteLink.setBaseUrl("userAction.do");
        deleteLink.addParameter("method", "deleteCustodian");
        deleteLink.addParameter("userId", user.getId());
        sb.append(deleteLink.getLink(LinkBuilder.LINK_TEXT, true));

        return sb.toString();

    }

    public String getUserManagementActions() {

        User user = (User) getCurrentRowObject();

        StringBuilder sb = new StringBuilder();

        LinkBuilder editLink = new LinkBuilder();
        editLink.setName("Edit");
        editLink.setBaseUrl("userAction.do");
        editLink.addParameter("method","viewEditUser");
        editLink.addParameter("userId", user.getId());

        sb.append(editLink.getLink(LinkBuilder.LINK_TEXT, true));

        LinkBuilder viewEquipmentLink = new LinkBuilder();
        viewEquipmentLink.setName("Equipment");
        viewEquipmentLink.setBaseUrl("userAction.do");
        viewEquipmentLink.addParameter("method","viewUserProfile");
        viewEquipmentLink.addParameter("userId", user.getId());

        sb.append("&nbsp;");

        sb.append(viewEquipmentLink.getLink(LinkBuilder.LINK_TEXT, true));

        return sb.toString();
    }

}
